﻿using System;
using System.Collections.Generic;
using System.Text;

using E.Model;
using E.DAL;
using E.Enum;

namespace E.BLL
{
    public class ExamBLL
    {
        private ExamDAL dal;

        public ExamBLL()
        {
            dal = new ExamDAL();
        }

        /// <summary>
        /// 获取试卷类型
        /// </summary>
        /// <returns></returns>
        public Dictionary<int, string> GetExamCategory()
        {
            return dal.GetExamCategory();
        }

        /// <summary>
        /// 获取课程考试列表
        /// </summary>
        /// <param name="userid"></param>
        /// <returns></returns>
        public IList<ShortExamInfoModel> GetExamList(int userid)
        {
            return dal.GetExamList(userid);
        }

        /// <summary>
        /// 获取试卷模板列表
        /// </summary>
        /// <param name="userid"></param>
        /// <returns></returns>
        public IList<ExamDefaultModel> GetExamDefaultList()
        {
            return dal.GetExamDefaultList();
        }

        /// <summary>
        /// 获取考试列表
        /// </summary>
        /// <param name="searchModel"></param>
        /// <param name="pageSize"></param>
        /// <param name="pageIndex"></param>
        /// <returns></returns>
        public ExamListModel GetExamListByCondition(SearchExamModel searchModel, int pageSize, int pageIndex)
        {
            return dal.GetExamListByCondition(searchModel, pageSize, pageIndex);
        }

        /// <summary>
        /// 获取试卷模板列表
        /// </summary>
        /// <param name="searchModel"></param>
        /// <param name="pageSize"></param>
        /// <param name="pageIndex"></param>
        /// <returns></returns>
        public ExamDefaultListModel GetExamDefaultListByCondition(SearchExamModel searchModel, int pageSize, int pageIndex)
        {
            return dal.GetExamDefaultListByCondition(searchModel, pageSize, pageIndex);
        }

        /// <summary>
        /// 获取自定义题目
        /// </summary>
        /// <param name="questionIDStr"></param>
        /// <returns></returns>
        public IList<int> GetExamCustomQuestionArray(string[] questionIDStr)
        {
            IList<int> questionList = new List<int>();
            foreach (string item in questionIDStr)
            {
                if (item != "")
                {
                    int quesItem = Convert.ToInt32(item);
                    questionList.Add(quesItem);
                }
            }
            return questionList;
        }

        #region wnan

        public PaperInspectListModel GetPaperInspectListModelByCondition(SearchExamModel searchModel, int pageSize, int pageIndex)
        {
            return dal.GetPaperInspectListModelByCondition(searchModel,pageSize,pageIndex);
        }

        public QuestionStaticsListModel GetQuestionStaticListModelByCondition(SearchExamModel searchModel, int pageSize, int pageIndex)
        {
            return dal.GetQuestionStaticListModelByCondition(searchModel, pageSize, pageIndex);
        }

        /// <summary>
        /// 管理员可统计每个老师所开设班级考试平均成绩，学习人数
        /// </summary>
        /// <param name="searchModel"></param>
        /// <param name="pageSize"></param>
        /// <param name="pageIndex"></param>
        /// <returns></returns>
        public AverageStaticsListModel GetAverageScoreStaticListModelByCondition(SearchExamModel searchModel, int pageSize, int pageIndex)
        {
            return dal.GetAverageScoreStaticListModelByCondition(searchModel, pageSize, pageIndex);
        }
        #endregion

        /// <summary>
        /// 获取试卷信息
        /// </summary>
        /// <param name="id"></param>
        /// <param name="categoryid"></param>
        /// <returns></returns>
        public ExamInfoModel GetExamInfo(int id, EnumExamCategory categoryid)
        {
            ExamInfoModel model = new ExamInfoModel();
            switch (categoryid)
            {
                case EnumExamCategory.CertificateExam:
                    model = dal.GetExam2CertificateInfo(id);
                    break;
                case EnumExamCategory.CourseExam:
                    model = dal.GetExam2CourseInfo(id);
                    break;
                default: break;
            }
            return model;
        }

        /// <summary>
        /// 获取试卷地区列表
        /// </summary>
        /// <param name="examid"></param>
        /// <returns></returns>
        public Dictionary<int, string> GetExamAreaList(int examid)
        {
            return dal.GetExamAreaList(examid);
        }

        /// <summary>
        /// 获取考试信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ExamInfoModel GetExamInfoByID(int id)
        {
            return dal.GetExamInfoByID(id);
        }

        /// <summary>
        /// 检查学员是否已经参加过考试
        /// </summary>
        /// <param name="userid"></param>
        /// <param name="examid"></param>
        /// <param name="category"></param>
        /// <returns></returns>
        public int GetTestInfo(int userid, int examid, EnumExamCategory category)
        {
            return dal.GetTestInfo(userid, examid, category);
        }

        /// <summary>
        /// 获取认证考试ID
        /// </summary>
        /// <param name="userid"></param>
        /// <param name="areaid"></param>
        /// <returns></returns>
        public IList<int> GetCertificateTestID(int userid, int areaid)
        {
            return dal.GetCertificateTestID(userid, areaid);
        }

        /// <summary>
        /// 添加试卷信息
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int AddExam(ExamInfoModel model)
        {
            return dal.AddExam(model);
        }

        /// <summary>
        /// 更新试卷信息
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int UpdateExam(ExamInfoModel model)
        {
            return dal.UpdateExam(model);
        }

        /// <summary>
        /// 添加试卷模板
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int AddExamDefault(ExamDefaultModel model)
        {
            return dal.AddExamDefault(model);
        }

        /// <summary>
        /// 更新试卷模板
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int UpdateExamDefault(ExamDefaultModel model)
        {
            return dal.UpdateExamDefault(model);
        }

        /// <summary>
        /// 获取模板信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ExamDefaultModel GetExamDefaultByID(int id)
        {
            return dal.GetExamDefaultByID(id);
        }

        /// <summary>
        /// 获取成绩列表
        /// </summary>
        /// <param name="searchModel"></param>
        /// <param name="pageSize"></param>
        /// <param name="pageIndex"></param>
        /// <returns></returns>
        public ScoreListModel SearchScoreByCondition(SearchScoreModel searchModel, int pageSize, int pageIndex)
        {
            return dal.SearchScoreByCondition(searchModel, pageSize, pageIndex);
        }

        /// <summary>
        /// 获取所有成绩数据
        /// </summary>
        /// <param name="searchModel"></param>
        /// <returns></returns>
        public IList<ShortScoreModel> GetAllScore(SearchScoreModel searchModel)
        {
            return dal.GetAllScore(searchModel);
        }

        /// <summary>
        /// 获取试卷题目设置
        /// </summary>
        /// <param name="examid"></param>
        /// <returns></returns>
        public IList<ExamSettingModel> GetExamQuestionSetting(int examid)
        {
            return dal.GetExamQuestionSetting(examid);
        }

        /// <summary>
        /// 获取试卷各题型设置
        /// </summary>
        /// <param name="examid"></param>
        /// <param name="questionCategoryID"></param>
        /// <returns></returns>
        public IList<ExamDetailSettingModel> GetExamDetailSetting(int examid, int questionCategoryID)
        {
            return dal.GetExamDetailSetting(examid, questionCategoryID);
        }

        /// <summary>
        /// 获取课程ID通过考试ID
        /// </summary>
        /// <param name="examid"></param>
        /// <returns></returns>
        public int GetCourseIDByExamID(int examid)
        {
            return dal.GetCourseIDByExamID(examid);
        }

        /// <summary>
        /// 获取试卷简单设置
        /// </summary>
        /// <param name="examid"></param>
        /// <returns></returns>
        public IList<ShortExamSettingModel> GetExamShortSetting(int examid)
        {
            return dal.GetExamShortSetting(examid);
        }

        /// <summary>
        /// 获取课程考试列表
        /// </summary>
        /// <param name="userid"></param>
        /// <param name="areaid"></param>
        /// <returns></returns>
        public IList<ShortExamInfoModel> GetCourseExamList(int userid, int areaid)
        {
            return dal.GetCourseExamList(userid, areaid);
        }

        /// <summary>
        /// 删除题目
        /// </summary>
        /// <param name="examid"></param>
        /// <returns></returns>
        public int DelExam(string[] examid)
        {
            return dal.DelExam(examid);
        }

        /// <summary>
        /// 删除模板
        /// </summary>
        /// <param name="examid"></param>
        /// <returns></returns>
        public int DelExamDefault(string[] examid)
        {
            return dal.DelExamDefault(examid);
        }
        /// <summary>
        /// 获取用户课程考试成绩
        /// </summary>
        /// <param name="userid"></param>
        /// <returns></returns>
        public IList<ShortScoreModel> GetUserCourseScoreList(int userid)
        {
            return dal.GetUserCourseScoreList(userid);
        }

        #region 用户成绩统计

        /// <summary>
        /// 获取用户口试与平时成绩
        /// </summary>
        /// <param name="userid"></param>
        /// <param name="category"></param>
        /// <returns></returns>
        public int GetSetScore(int userid, int category)
        {
            return dal.GetSetScore(userid, category);
        }

        /// <summary>
        /// 学员成绩输入
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int UserInputScoreHandle(InputModel model)
        {
            return dal.UserInputScoreHandle(model);
        }

        /// <summary>
        /// 获取输入成绩列表
        /// </summary>
        /// <param name="searchModel"></param>
        /// <returns></returns>
        public IList<ShortScoreInputModel> GetScoreInputList(SearchScoreInputModel searchModel)
        {
            return dal.GetScoreInputList(searchModel);
        }

        /// <summary>
        /// 获取用户认证考试成绩
        /// </summary>
        /// <param name="userid"></param>
        /// <param name="areaid"></param>
        /// <returns></returns>
        public ShortScoreModel GetCertificateScore(int userid, int areaid)
        {
            return dal.GetCertificateScore(userid, areaid);
        }

        /// <summary>
        /// 获取用户所有课程成绩
        /// </summary>
        /// <param name="userid"></param>
        /// <returns></returns>
        public IList<int> GetUserCourseScore(int userid)
        {
            return dal.GetUserCourseScore(userid);
        }

        /// <summary>
        /// 获取用户输入成绩信息
        /// </summary>
        /// <param name="userid"></param>
        /// <returns></returns>
        public ScoreLogModel GetUserInputScoreInfo(int userid)
        {
            return dal.GetUserInputScoreInfo(userid);
        }

        #endregion

        /// <summary>
        /// 获取测试的开始结束时间与考试时间
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ShortExamInfoModel GetShortExamInfo(int id)
        {
            return dal.GetShortExamInfo(id);
        }

        /// <summary>
        /// 获取用户进入考试时间
        /// </summary>
        /// <param name="examid"></param>
        /// <param name="userid"></param>
        /// <returns></returns>
        public ShortTestModel GetUserTestStartTime(int examid, int userid)
        {
            return dal.GetUserTestStartTime(examid, userid);
        }

        /// <summary>
        /// 更新考试信息
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int UpdateTestInfo(TestModel model)
        {
            return dal.UpdateTestInfo(model);
        }

        /// <summary>
        /// 获取成绩比例列表
        /// </summary>
        /// <returns></returns>
        public IList<ScoreCategoryModel> GetScoreCategoryList()
        {
            return dal.GetScoreCategoryList();
        }

        /// <summary>
        /// 获取输入成绩类别列表
        /// </summary>
        /// <returns></returns>
        public IDictionary<int, string> GetInputScoreCategoryList()
        {
            return dal.GetInputScoreCategoryList();
        }

        #region 内训

        /// <summary>
        /// 获取内训课程考试列表
        /// </summary>
        /// <param name="userid"></param>
        /// <returns></returns>
        public IList<ShortExamInfoModel> GetInternalCourseExamList(int userid)
        {
            return dal.GetInternalCourseExamList(userid);
        }

        /// <summary>
        /// 获取内训用户输入成绩信息
        /// </summary>
        /// <param name="userid"></param>
        /// <returns></returns>
        public ScoreLogModel GetInternalUserInputScoreInfo(int userid)
        {
            return dal.GetInternalUserInputScoreInfo(userid);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="userid"></param>
        /// <returns></returns>
        public IList<ScoreModel> GetInternalUserScoreLog(int userid)
        {
            return dal.GetInternalUserScoreLog(userid);
        }

        /// <summary>
        /// 学员成绩输入
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int InternalUserInputScoreHandle(InputModel model)
        {
            return dal.InternalUserInputScoreHandle(model);
        }

        /// <summary>
        /// 获取内训课程考试列表（补考）
        /// </summary>
        /// <param name="userid"></param>
        /// <returns></returns>
        public IList<ShortExamInfoModel> GetInternalSecCourseExamList(int userid)
        {
            return dal.GetInternalSecCourseExamList(userid);
        }

        /// <summary>
        /// 获取原考试ID
        /// </summary>
        /// <param name="userid"></param>
        /// <param name="examid"></param>
        /// <returns></returns>
        public int GetOriginalTestID(int userid, int examid)
        {
            return dal.GetOriginalTestID(userid, examid);
        }

        /// <summary>
        /// 更新补考
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int UpdateUserSecTest(TestModel model)
        {
            return dal.UpdateUserSecTest(model);
        }

        /// <summary>
        /// 获取成绩列表
        /// </summary>
        /// <param name="searchModel"></param>
        /// <param name="pageSize"></param>
        /// <param name="pageIndex"></param>
        /// <returns></returns>
        public ScoreListModel getInternalScoreByCondition(SearchScoreModel searchModel, int pageSize, int pageIndex)
        {
            return dal.getInternalScoreByCondition(searchModel, pageSize, pageIndex);
        }

        /// <summary>
        /// 获取用户课程考试成绩
        /// </summary>
        /// <param name="userid"></param>
        /// <returns></returns>
        public IDictionary<string, int> GetCourseScore(int userid)
        {
            return dal.GetCourseScore(userid);
        }

        /// <summary>
        /// 获取用户课程考试成绩
        /// </summary>
        /// <param name="userid"></param>
        /// <returns></returns>
        public IDictionary<string, int> GetProjectScore(int userid)
        {
            return dal.GetProjectScore(userid);
        }

        /// <summary>
        /// 获取用户输入成绩
        /// </summary>
        /// <param name="userid"></param>
        /// <returns></returns>
        public IDictionary<string, int> GetInputScore(int userid)
        {
            return dal.GetInputScore(userid);
        }

        #endregion

        #region 公共课

        /// <summary>
        /// 获取公共课考试列表
        /// </summary>
        /// <param name="searchModel"></param>
        /// <param name="pageSize"></param>
        /// <param name="pageIndex"></param>
        /// <returns></returns>
        public ExamListModel GetInternalPublicExamListByCondition(SearchExamModel searchModel, int pageSize, int pageIndex)
        {
            return dal.GetInternalPublicExamListByCondition(searchModel, pageSize, pageIndex);
        }

        /// <summary>
        /// 获取内训课程考试列表
        /// </summary>
        /// <param name="userid"></param>
        /// <returns></returns>
        public IList<ShortExamInfoModel> GetPublicCourseExamList(int userid)
        {
            return dal.GetPublicCourseExamList(userid);
        }

        #endregion

        #region 内训 成绩

        /// <summary>
        /// 成绩类别列表
        /// </summary>
        /// <returns></returns>
        public IDictionary<int, string> GetInternalScoreCategoryList()
        {
            return dal.GetInternalScoreCategoryList();
        }

        /// <summary>
        /// 添加类别
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public int AddScoreCategory(string name)
        {
            return dal.AddScoreCategory(name);
        }

        /// <summary>
        /// 更新类别
        /// </summary>
        /// <param name="id"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public int UpdateScoreCategory(int id, string name)
        {
            return dal.UpdateScoreCategory(id, name);
        }

        /// <summary>
        /// 检查类别名称是否重复
        /// </summary>
        /// <param name="coursename"></param>
        /// <param name="selfid"></param>
        /// <returns></returns>
        public bool CheckExistCategoryName(string name, int selfid)
        {
            return dal.CheckExistCategoryName(name, selfid);
        }

        /// <summary>
        /// 获取类别名称
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public string GetScoreCategoryInfo(int id)
        {
            return dal.GetScoreCategoryInfo(id);
        }

        /// <summary>
        /// 删除题目
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public int DelScoreCategory(string[] id)
        {
            return dal.DelScoreCategory(id);
        }

        #endregion
    }
}
